/**
 * Definition for singly-linked list.
 * class ListNode {
 *     val: number
 *     next: ListNode | null
 *     constructor(val?: number, next?: ListNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.next = (next===undefined ? null : next)
 *     }
 * }
 */
//   class ListNode {
//       val: number
//       next: ListNode | null
//       constructor(val?: number, next?: ListNode | null) {
//           this.val = (val===undefined ? 0 : val)
//           this.next = (next===undefined ? null : next)
//       }
//   }

 function reversePrint(head: ListNode | null): number[] {
    let stack:number[]= [];
    let node = head;
 
    while(node != null){
      stack.push(node.val);
      node = node.next;
    }
 
    // let result = stack.reverse();
    let result:number[] = [];
    while(stack.length > 0){
        let v = stack.pop();
        if(v != null){
            result.push(v);
        }
    }
    return result;
 };


